package com.duomai.myapplication.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;

import com.duomai.myapplication.R;
import com.example.admin.SQLite.User;
import com.example.admin.Utils.SimpleSpinner;
import com.example.admin.base.BaseActivity;
import com.example.admin.bean.PersonalBean;
import com.orhanobut.hawk.Hawk;

import java.util.ArrayList;
import java.util.Arrays;

//个人信息
public class PersonalActivity extends BaseActivity {
    SimpleSpinner spinner2, spinner3;
    EditText tvName, tvPhone, tvEmail;
    SimpleSpinner spinner1;
    User user;
    @Override
    public void setContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_personal);
          user = Hawk.get("user");

        spinner1 = findViewById(R.id.spinner1);
        spinner2 = findViewById(R.id.spinner2);
        spinner3 = findViewById(R.id.spinner3);
        tvName = findViewById(R.id.tvName);
        tvPhone = findViewById(R.id.tvPhone);
        tvEmail = findViewById(R.id.tvEmail);

        ArrayList<String> list = new ArrayList<>();
        for (int i = 1; i < 100; i++) {
            list.add(i + "幢");
        }
        spinner1.setContent(list);
        ArrayList<String> list1 = new ArrayList<>();
        String[] data = getResources().getStringArray(R.array.data2);
        list1=new ArrayList<>(Arrays.asList(data));
        spinner2.setContent(list1);
        ArrayList<String> list2 = new ArrayList<>();
        String[] data3 = getResources().getStringArray(R.array.data3);
        list2=new ArrayList<>(Arrays.asList(data3));
        spinner3.setContent(list2);
        if (Hawk.contains("PersonalBean" + user.id)){
            PersonalBean bean= Hawk.get("PersonalBean" + user.id);
            tvName.setText(bean.name);
            tvPhone.setText(bean.phone);
            tvEmail.setText(bean.smaill);
            Log.e(TAG, "setContentView: "+bean.zhaung );
            Log.e(TAG, "setContentView: "+bean.dy );
            Log.e(TAG, "setContentView: "+bean.si );
            spinner1.setDefaultContent(bean.zhaung);
            spinner2.setDefaultContent(bean.dy);
            spinner3.setDefaultContent(bean.si);
        }
        findViewById(R.id.tvSure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str = tvName.getText().toString().trim();
                String str1 = tvPhone.getText().toString().trim();
                String str2 = tvEmail.getText().toString().trim();
                String s1 = (String) spinner1.getSelectedItem();
                String s2 = (String) spinner2.getSelectedItem();
                String s3 = (String) spinner3.getSelectedItem();
                PersonalBean bean = new PersonalBean();
                bean.name = str;
                bean.phone = str1;
                bean.smaill = str2;
                bean.zhaung = s1;
                bean.dy = s2;
                bean.si = s3;
                bean.xq = user.UserAddress;
                bean.ZZ = s1 + s2 + s3;
                Hawk.put("PersonalBean" + user.id, bean);
                toast("保存成功");
            }
        });

    }

    @Override
    public void setInitView() {

    }
}